package com.ems.controller.supers.questions;

import com.ems.pojo.data.RequestData;
import com.ems.pojo.data.ResultData;
import com.ems.pojo.data.RetunResult;
import com.ems.pojo.data.ReturnPageResult;
import com.ems.pojo.questions.Judgment;
import com.ems.pojo.questions.Subject;
import com.ems.service.supers.questions.JudgmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2019/10/19
 * @Description: 判断题控制类
 * @Version: 1.0
 */
@Controller
@CrossOrigin //允许所有请求跨域
@RequestMapping("/judgmentController")
public class JudgmentController {

    @Autowired
    @Qualifier("judgmentService")
    private JudgmentService judgmentService;

    /**
     * 添加判断题
     * @param judgmentList
     * @return
     */
    @ResponseBody
    @RequestMapping("/addJudgment")
    public ResultData addJudgment(@RequestBody List<Judgment> judgmentList){
        judgmentService.addJudgment(judgmentList);
        return RetunResult.AssemblyData();
    }

    /**
     * 删除对应的判断题
     * @param judgmentList
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteJudgment")
    public ResultData deleteJudgment(@RequestBody List<Judgment> judgmentList){
        judgmentService.deleteJudgment(judgmentList);
        return RetunResult.AssemblyData();
    }

    /**
     * 修改对应的判断题
     * @param judgment
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateJudgment")
    public ResultData updateJudgment(@RequestBody Judgment judgment){
        judgmentService.updateJudgment(judgment);
        return RetunResult.AssemblyData();
    }

    /**
     * 根据条件查询判断题
     * @param requestData
     * @return
     */
    @ResponseBody
    @RequestMapping("/findJudgment")
    public ResultData findJudgment(@RequestBody RequestData requestData){
        ReturnPageResult.setPageHelperInfo(requestData);
        List<Subject> list = judgmentService.findJudgment(requestData);
        return ReturnPageResult.AssemblyData(list);
    }


}
